package com.nexus.all.manager;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nexus.all.dao.NoteWordMapper;
import com.nexus.all.dto.NoteWordQueryDTO;
import com.nexus.all.model.NoteWord;
import com.nexus.bean.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class NoteWordManager extends ServiceImpl<NoteWordMapper, NoteWord> {

    public List<NoteWord> getByWords(List<String> words) {
        LambdaQueryWrapper<NoteWord> wrapper = NoteWord.gw();
        wrapper.in(NoteWord::getNoteWord, words);
        return list(wrapper);
    }


    public Page<NoteWord> queryNoteWord(NoteWordQueryDTO dto) {
        Page<NoteWord> page = new Page<>();
        page.setCurrent(dto.getPageNo());
        page.setSize(dto.getPageSize());

        LambdaQueryWrapper<NoteWord> queryWrapper = NoteWord.gw();
        if (StringUtils.isNotBlank(dto.getKeyword())) {
            queryWrapper.like(NoteWord::getNoteWord, dto.getKeyword());
        }
        return page(page, queryWrapper);
    }
}